import * as qiniu from 'qiniu-js'

export default function(file){
  return new Promise((resolve, reject) =>{
    _request({ url: 'common/getQiniuToken' })
    .then(({ret: token}) =>{
      var key = 'image/' + new Date().getTime() + file.name
      var obs = qiniu.upload(file, key, token)
      var cb = {
        complete: ({key}) => resolve(Vue._GLOBAL.qiniuPic + key),
        error: reject
      }
      obs.subscribe(cb)
    })
  })
}